package com.seteam.collabcrossword.messages.server;

import com.seteam.collabcrossword.CollabCrosswordUtils;
import com.seteam.collabcrossword.Coordinates;
import com.seteam.collabcrossword.Globals;
import com.seteam.collabcrossword.exceptions.CoordinatesException;
import com.seteam.collabcrossword.messages.Message;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * When the client requests for a lock on a word, if the server is able to lock it,
 * it uses this message to send the coordinates of the locked word to the client. The client
 * can then use the coordinates to unlock the tiles on the UI
 */
public class LockedWord implements Message, Serializable {
    private static final long serialVersionUID = 8346380990229860303L;
    private List<Coordinates> lockedCoordinates;

    /**
     * Constructor
     */
    public LockedWord() {
        lockedCoordinates = new ArrayList<Coordinates>();
    }

    /**
     * Adds a coordinate to the list of coordinates that represents
     * the locked word
     *
     * @param coordinates the coordinates to be added
     * @throws CoordinatesException if the value that is passed is null
     */
    public void addCoordinates(final Coordinates coordinates)
            throws CoordinatesException {
        CollabCrosswordUtils.checkNotNull(coordinates, Globals.LOCKED_WORD_ERROR + "Cannot add a " +
                "null coordinate to the list of locked coordinates");
        lockedCoordinates.add(coordinates);
    }

    /**
     * Getter for lockedCoordinates
     *
     * @return the list of coordinates that have been locked
     */
    public List<Coordinates> getLockedCoordinates() {
        return lockedCoordinates;
    }

    /**
     * {@inheritDoc}
     */
    public String getAction() {
        return Globals.LOCKED_WORD;
    }
}
